﻿using System;
using System.Collections.Generic;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;

namespace BoldBrick.SharePoint.CommonControls.DataObjects.Base
{
	/// <summary>
	/// Base metadata class for <see cref="SPField"/> object
	/// </summary>
	public class ListColumn
	{
		private readonly string resourceFileName;
		private readonly string displayNameResourceKey;

		#region ------ Properties -----------------------------------------------------------------

		/// <summary>
		/// Internal name of the field
		/// </summary>
		public string InternalName { get; private set;  }

		/// <summary>
		/// Gets/sets ID of the field
		/// </summary>
		public Guid? ID { get; set; }

		/// <summary>
		/// Gets/sets showing of the field in new form
		/// </summary>
		public bool? ShowInNewForm { get; set; }

		/// <summary>
		/// Gets/sets showing of the field in display form
		/// </summary>
		public bool? ShowInDisplayForm { get; set; }

		/// <summary>
		/// Gets/sets showing of the field in edit form
		/// </summary>
		public bool? ShowInEditForm { get; set; }

		/// <summary>
		/// Gets/sets if this field is required
		/// </summary>
		public bool? Required { get; set; }

		/// <summary>
		/// Gets/sets description of the field
		/// </summary>
		public string Description { get; set; }

		/// <summary>
		/// Gets/sets if columns is hidden
		/// </summary>
		public bool? Hidden { get; set; }

		private List<ListColumnProperty> properties;
		/// <summary>
		/// Custom properties of the field
		/// </summary>
		public List<ListColumnProperty> Properties
		{
			get
			{
				if (properties == null)
					properties = new List<ListColumnProperty>();

				return properties;
			}
		}

		#endregion

		#region ------ Constructors ---------------------------------------------------------------

		/// <summary>
		/// Creates new instance of <see cref="ListColumn"/> class.
		/// </summary>
		/// <param name="resourceFileName">Resource file name without ".cz-cs.resx" extension</param>
		/// <param name="displayNameResourceKey">Resource key name</param>
		/// <param name="internalName">Internal name of the field</param>
		public ListColumn(string resourceFileName, string displayNameResourceKey, string internalName)
		{
			this.resourceFileName = resourceFileName;
			this.displayNameResourceKey = displayNameResourceKey;
			this.InternalName = internalName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Gets localized display name
		/// </summary>
		/// <param name="language">Language of the display name</param>
		/// <returns>Returns localized display name</returns>
		public string GetDisplayName(uint language)
		{
			string source = string.Format("$Resources:{0}", this.displayNameResourceKey);
			return SPUtility.GetLocalizedString(source, this.resourceFileName, language);
		}

		public override string ToString()
		{
			return this.InternalName;
		}

		#endregion


	}
}